package control.panel
{
	import events.LoginEvent;
	
	import global.GameState;
	
	import view.panel.prompt.AlertPanel;

	public class AlertPanelControl extends PanelControl
	{
		public function AlertPanelControl()
		{
			initPanel();
			initListener();
		}
		
		private function initListener():void
		{
			_model.loginModel.addEventListener(LoginEvent.ACCESSSERVER_LOGINING,onAccessLogining);
			_model.loginModel.addEventListener(LoginEvent.SUCCESS,onAccessSuccess);
		}
		
		private function onAccessSuccess(event:LoginEvent):void
		{
			close();
		}
		
		private function onAccessLogining(event:LoginEvent):void
		{
			if (GameState.traceType == 3)
			{
				alert("连接服务器中，请稍等...: snsId:" + GameState.snsId + " snsKey:" + GameState.snsKey);
			}
			else
			{
				alert("连接服务器中，请稍等...");
			}
		}
		
		private function initPanel():void
		{
			_view.alertPanel = new AlertPanel(this);
		}
		
		public function alert(content:String):void
		{
			if (content)
			{
				_view.alertPanel.alert(content);
				_view.alertPanel.open();
				_control.sceneControl.lockWorld();
			}
		}
		
		public function close():void
		{
			_view.alertPanel.close();
			_control.sceneControl.unlockWorld();
		}
	}
}